import 'package:firebase_analytics/firebase_analytics.dart';

///
/// Created by hai046 on 2022/12/2 09:47.
///

class FirebaseAnalyticsUtils {
  static final FirebaseAnalyticsUtils _firebaseAnalyticsUtils =
      FirebaseAnalyticsUtils._();

  FirebaseAnalytics? _firebaseAnalytics;

  factory FirebaseAnalyticsUtils() => _firebaseAnalyticsUtils;

  FirebaseAnalyticsUtils._();

  Future<String> init() async {
    _firebaseAnalytics = FirebaseAnalytics.instance;
    var appInstanceId = await _firebaseAnalytics?.appInstanceId ?? "";
    //TODO wangchao
    // if (appInstanceId.isNotEmpty) {
    //   //加入用户属性
    //   SourceDataSdkManager.setUserCustomProperty(
    //       customKey: firebase_uid, customValue: appInstanceId);
    //   //上传用户属性
    //   SourceDataSdkManager.trackUserChange();
    //
    //   FirebaseModel.setFirebaseUid(uid: appInstanceId);
    // }
    return appInstanceId;
  }

  void setUserId(int? user) {
    if (user != null) {
      _firebaseAnalytics?.setUserId(id: '$user');
    }
  }

  void setUserProperty(String name, String value) {
    _firebaseAnalytics?.setUserProperty(name: name, value: value);
  }
}
